import os
# 文件名： Server2025
# 描  述：
# 作  者： besti
# 日  期： 2025/4/15
#  Have you ever seen Los Angeles at 4 a.m?
import socket

# 创建 socket 对象
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 绑定地址和端口
server_address = ('localhost', 8888)
server_socket.bind(server_address)

# 监听连接
server_socket.listen(1)
print('服务器正在监听 {}:{}'.format(*server_address))

# 接受客户端连接
client_socket, client_address = server_socket.accept()
print('接受来自 {} 的连接'.format(client_address))

while True:
    # 接收客户端消息
    data = client_socket.recv(1024).decode('utf-8')
    if not data:
        break
    print('客户端说: {}'.format(data))

    # 发送消息给客户端
    message = input('请输入要发送给客户端的消息: ')
    client_socket.send(message.encode('utf-8'))
    if input("是否要继续？Y/N")=="N":
        break

# 关闭连接
client_socket.close()
server_socket.close()